package com.bwie.sixth.house.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;


import com.bwie.sixth.house.config.JwtUtil;
import com.bwie.sixth.house.config.PageUtil;
import com.bwie.sixth.house.vo.OldEsQuaryVo;
import com.bwie.sixth.house.vo.RentEsQuaryVo;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.sixth.house.entity.RentHouseEntity;
import com.bwie.sixth.house.service.RentHouseService;

import javax.servlet.http.HttpServletRequest;


/**
 * 
 *
 * @author lzl
 * @email 1601711944@gmail.com
 * @date 2021-10-16 09:57:43
 */
@RestController
@RequestMapping("house/renthouse")
public class RentHouseController {
    @Autowired
    private RentHouseService rentHouseService;
    @Autowired
    private JwtUtil jwtUtil;
    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = rentHouseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{rentId}")

    public R info(@PathVariable("rentId") Integer rentId){
		RentHouseEntity rentHouse = rentHouseService.getById(rentId);

        return R.ok().put("rentHouse", rentHouse);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody RentHouseEntity rentHouse){
		rentHouseService.save(rentHouse);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody RentHouseEntity rentHouse){
		rentHouseService.updateById(rentHouse);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Integer[] rentIds){
		rentHouseService.removeByIds(Arrays.asList(rentIds));

        return R.ok();
    }

    @RequestMapping("rentEsList")
    public PageUtil RentEsList(@RequestBody RentEsQuaryVo rentEsQuaryVo, @RequestParam(value = "size",defaultValue = "3")int size,
                               @RequestParam(value = "page",defaultValue = "1") int page) throws IOException {

//        String token = request.getHeader("token");
//        System.out.println(token);
//        Claims claims = jwtUtil.parseJWT(token);
//        System.out.println(claims);
//        if (claims!=null){
//            return rentHouseService.rentEsList(rentEsQuaryVo,size,page);
//        }
//        return null;
        return rentHouseService.rentEsList(rentEsQuaryVo,size,page);
    }
}
